﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DingApi.Models;
using System.Data;

using System.Web;
using Dingding.Helper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


namespace DingApi.Controllers
{
    [RoutePrefix("api/Pmmm02n")]
    public class Pmmm02nController : ApiController
    {

        /// <summary>
        /// 查询标签记录
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PostPmmm02n_Inq")]
        public System.Data.DataSet PostPmmm02n_Inq([FromBody]  JObject obj)
        {
            EI.EIInfo inBlock = new EI.EIInfo();
          
             
          
           
          


            string MAT_NO = obj["MAT_NO"] == null ? " " : obj["MAT_NO"].ToString();
            string QUAL_GRADE_CODE = obj["QUAL_GRADE_CODE"] == null ? " " : obj["QUAL_GRADE_CODE"].ToString();
            string DPTMENT_CODE = obj["DPTMENT_CODE"] == null ? " " : obj["DPTMENT_CODE"].ToString();


            string SHIFT_GROUP = obj["SHIFT_GROUP"] == null ? " " : obj["SHIFT_GROUP"].ToString();
            string DUTY_MAKER = obj["DUTY_MAKER"] == null ? " " : obj["DUTY_MAKER"].ToString();


            string PROD_LOT_NO = obj["PROD_LOT_NO"] == null ? " " : obj["PROD_LOT_NO"].ToString();
            string REC_REVISOR = obj["REC_REVISOR"] == null ? " " : obj["REC_REVISOR"].ToString();
            string REC_CREATE_TIME = obj["REC_CREATE_TIME"] == null ? " " : obj["REC_CREATE_TIME"].ToString();
            string REC_REVISE_TIME = obj["REC_REVISE_TIME"] == null ? " " : obj["REC_REVISE_TIME"].ToString();

 

            string page_no = obj["PAGE_NO"] == null ? " " : obj["PAGE_NO"].ToString();
            string page_size = obj["PAGE_SIZE"] == null ? " " : obj["PAGE_SIZE"].ToString();
            string type_inq = obj["TYPE_INQ"] == null ? " " : obj["TYPE_INQ"].ToString();

            string userid = obj["USERID"] == null ? " " : obj["USERID"].ToString();
            string USERNAME = obj["USERNAME"] == null ? " " : obj["USERNAME"].ToString();

            string FORMNAME = obj["FORMNAME"] == null ? " " : obj["FORMNAME"].ToString();
            string PRO_TYPE = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString();


            string STATUS = "";

            //入库申请回退PB14 ；14->11；PA17 质量确认 14->17
            if (PRO_TYPE== "PB14" || PRO_TYPE == "PA15") 
            {
                STATUS = "14";
            }
            else if (PRO_TYPE == "PB15" || PRO_TYPE == "PA17")
            {
                STATUS = "15";
            }
            else if (PRO_TYPE == "PB17" || PRO_TYPE == "PA19" ) //质量确认回退，PA17入库确认
            {
                STATUS = "17";
            }

            else if (PRO_TYPE == "PB19") //入库确认回退
            {
                STATUS = "19";
            }






            inBlock.Tables[0].Columns.Add("MAT_NO");
            inBlock.Tables[0].Columns.Add("QUAL_GRADE_CODE"); 
            inBlock.Tables[0].Columns.Add("DPTMENT_CODE");  

            inBlock.Tables[0].Columns.Add("SHIFT_GROUP");
            inBlock.Tables[0].Columns.Add("DUTY_MAKER");
         

            inBlock.Tables[0].Columns.Add("PROD_LOT_NO");
            inBlock.Tables[0].Columns.Add("REC_REVISOR");
            inBlock.Tables[0].Columns.Add("REC_CREATE_TIME");
            inBlock.Tables[0].Columns.Add("REC_REVISE_TIME");
            inBlock.Tables[0].Columns.Add("STATUS");


             


            inBlock.Tables[0].Rows.Add();
            inBlock.sys_info.company_code = "LT";
            inBlock.sys_info.userid = userid;

            inBlock.Tables[0].Rows[0]["MAT_NO"] = MAT_NO;
            inBlock.Tables[0].Rows[0]["QUAL_GRADE_CODE"] = QUAL_GRADE_CODE;
            inBlock.Tables[0].Rows[0]["DPTMENT_CODE"] = DPTMENT_CODE;

            inBlock.Tables[0].Rows[0]["SHIFT_GROUP"] = SHIFT_GROUP;
            inBlock.Tables[0].Rows[0]["DUTY_MAKER"] = DUTY_MAKER;

            inBlock.Tables[0].Rows[0]["PROD_LOT_NO"] = PROD_LOT_NO;
            inBlock.Tables[0].Rows[0]["REC_REVISOR"] = REC_REVISOR;


         

            //1表示高级查询
           // inBlock.Tables[0].Rows[0]["REC_CREATE_TIME"] = type_inq == "1" ? REC_CREATE_TIME : DateTime.Now.ToString("yyyyMMdd") + "000000";

            inBlock.Tables[0].Rows[0]["REC_CREATE_TIME"] = REC_CREATE_TIME;

            inBlock.Tables[0].Rows[0]["REC_REVISE_TIME"] = REC_REVISE_TIME;
            inBlock.Tables[0].Rows[0]["STATUS"] = STATUS;

         




            EF.DSUtility.PageInfoDataTable PageInfo = new EF.DSUtility.PageInfoDataTable();
            PageInfo.AddPageInfoRow((int.Parse(page_no) - 1) * int.Parse(page_size), int.Parse(page_size));

            inBlock.Tables.Add("PageInfo"); //后台需要
            inBlock.Tables["PageInfo"].Merge(PageInfo);
        
            string svr = "pmmm02n_inq"; ////高级查询
            //if (type_inq=="1")
            //{
            //    svr = "pmmm02n_inq2"; 
            //}
                
            EI.EIInfo outBlock = EI.EITuxedo.CallService(svr, inBlock);



            //图片数量
            if (!(outBlock.Tables[0].Columns.Contains("FIELD_N1")))
            {
                outBlock.Tables[0].Columns.Add("FIELD_N1");
            }




            string sql_str1 = "    select code,code_desc_1_content from tep0002   where code_class = 'QMQK' "
                              + "   and code_desc_2_content like '%N%'   ";
            //仓库代码转换
            EI.EIInfo outBlock_TEMP = EF.Utility.ExecQuery(sql_str1); //QUAL_GRADE_CODE


            //小代码转换；
            EI.EIInfo outBlock_TEMP2 = EF.Utility.GetCodeClassValue("MM08"); //SHIFT_GROUP


            DataTable dtTemp = null;


            for (int i = outBlock.Tables[0].Rows.Count - 1; i >= 0; i--)
            { 
                string qual_grade_code = outBlock.Tables[0].Rows[i]["QUAL_GRADE_CODE"].ToString().Trim();
                if (qual_grade_code.Trim() != "")
                {
                    if (outBlock_TEMP.Tables[0].Select("CODE  = '" + qual_grade_code + "'").Count<DataRow>() == 1)
                    {
                        dtTemp = outBlock_TEMP.Tables[0].Select("CODE  = '" + qual_grade_code + "'").CopyToDataTable<DataRow>();
                        outBlock.Tables[0].Rows[i]["QUAL_GRADE_CODE"] = dtTemp.Rows[0]["CODE_DESC_1_CONTENT"];
                    }
                }
                string shift_group = outBlock.Tables[0].Rows[i]["SHIFT_GROUP"].ToString().Trim();
                if (shift_group.Trim() != "")
                {
                    if (outBlock_TEMP2.Tables[0].Select("CODE  = '" + shift_group + "'").Count<DataRow>() == 1)
                    {
                        dtTemp = outBlock_TEMP2.Tables[0].Select("CODE  = '" + shift_group + "'").CopyToDataTable<DataRow>();
                        outBlock.Tables[0].Rows[i]["SHIFT_GROUP"] = dtTemp.Rows[0]["CODE_DESC_1_CONTENT"];
                    }
                }


                //UpDownFileFtpController ctr = new UpDownFileFtpController();
                //string mat_no = outBlock.Tables[0].Rows[i]["MAT_NO"].ToString();
                //int files_num = ctr.PostGetFilesNum("DCXA", mat_no, "");
                //outBlock.Tables[0].Rows[i]["FIELD_N1"] = files_num;



            }










            outBlock.Tables[0].TableName = "Table0";









            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);            
            return outBlock;


        }


        /// <summary>
        /// 查询标签记录汇总记录
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PostPmmm02n_Inq2")]
        public System.Data.DataSet PostPmmm02n_Inq2([FromBody]  JObject obj)
        {
            EI.EIInfo inBlock = new EI.EIInfo();

              

            string MAT_NO = obj["MAT_NO"] == null ? " " : obj["MAT_NO"].ToString();
            string QUAL_GRADE_CODE = obj["QUAL_GRADE_CODE"] == null ? " " : obj["QUAL_GRADE_CODE"].ToString();
            string DPTMENT_CODE = obj["DPTMENT_CODE"] == null ? " " : obj["DPTMENT_CODE"].ToString();


            string SHIFT_GROUP = obj["SHIFT_GROUP"] == null ? " " : obj["SHIFT_GROUP"].ToString();
            string DUTY_MAKER = obj["DUTY_MAKER"] == null ? " " : obj["DUTY_MAKER"].ToString();


            string PROD_LOT_NO = obj["PROD_LOT_NO"] == null ? " " : obj["PROD_LOT_NO"].ToString();
            string REC_REVISOR = obj["REC_REVISOR"] == null ? " " : obj["REC_REVISOR"].ToString();
            string REC_CREATE_TIME = obj["REC_CREATE_TIME"] == null ? " " : obj["REC_CREATE_TIME"].ToString();
            string REC_REVISE_TIME = obj["REC_REVISE_TIME"] == null ? " " : obj["REC_REVISE_TIME"].ToString();



            string page_no = obj["PAGE_NO"] == null ? " " : obj["PAGE_NO"].ToString();
            string page_size = obj["PAGE_SIZE"] == null ? " " : obj["PAGE_SIZE"].ToString();
            string type_inq = obj["TYPE_INQ"] == null ? " " : obj["TYPE_INQ"].ToString();

            string userid = obj["USERID"] == null ? " " : obj["USERID"].ToString();
            string USERNAME = obj["USERNAME"] == null ? " " : obj["USERNAME"].ToString();

            string FORMNAME = obj["FORMNAME"] == null ? " " : obj["FORMNAME"].ToString();
            string PRO_TYPE = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString();


            string STATUS = "";


            if (PRO_TYPE == "PB14" || PRO_TYPE == "PA15")
            {
                STATUS = "14";
            }
            else if (PRO_TYPE == "PB15" || PRO_TYPE == "PA17")
            {
                STATUS = "15";
            } 
            else if (PRO_TYPE == "PB17" || PRO_TYPE == "PA19") //质量确认回退，PA17入库确认
            {
                STATUS = "17";
            }

            else if (PRO_TYPE == "PB19") //入库确认回退
            {
                STATUS = "19";
            }






            inBlock.Tables[0].Columns.Add("MAT_NO");
            inBlock.Tables[0].Columns.Add("QUAL_GRADE_CODE");
            inBlock.Tables[0].Columns.Add("DPTMENT_CODE");

            inBlock.Tables[0].Columns.Add("SHIFT_GROUP");
            inBlock.Tables[0].Columns.Add("DUTY_MAKER");


            inBlock.Tables[0].Columns.Add("PROD_LOT_NO");
            inBlock.Tables[0].Columns.Add("REC_REVISOR");
            inBlock.Tables[0].Columns.Add("REC_CREATE_TIME");
            inBlock.Tables[0].Columns.Add("REC_REVISE_TIME");
            inBlock.Tables[0].Columns.Add("STATUS");


            


            inBlock.Tables[0].Rows.Add();
            inBlock.sys_info.company_code = "LT";
            inBlock.sys_info.userid = userid;

            inBlock.Tables[0].Rows[0]["MAT_NO"] = MAT_NO;
            inBlock.Tables[0].Rows[0]["QUAL_GRADE_CODE"] = QUAL_GRADE_CODE;
            inBlock.Tables[0].Rows[0]["DPTMENT_CODE"] = DPTMENT_CODE;

            inBlock.Tables[0].Rows[0]["SHIFT_GROUP"] = SHIFT_GROUP;
            inBlock.Tables[0].Rows[0]["DUTY_MAKER"] = DUTY_MAKER;

            inBlock.Tables[0].Rows[0]["PROD_LOT_NO"] = PROD_LOT_NO;
            inBlock.Tables[0].Rows[0]["REC_REVISOR"] = REC_REVISOR;




            //1表示高级查询
            // inBlock.Tables[0].Rows[0]["REC_CREATE_TIME"] = type_inq == "1" ? REC_CREATE_TIME : DateTime.Now.ToString("yyyyMMdd") + "000000";

            inBlock.Tables[0].Rows[0]["REC_CREATE_TIME"] = REC_CREATE_TIME;

            inBlock.Tables[0].Rows[0]["REC_REVISE_TIME"] = REC_REVISE_TIME;
            inBlock.Tables[0].Rows[0]["STATUS"] = STATUS;






            EF.DSUtility.PageInfoDataTable PageInfo = new EF.DSUtility.PageInfoDataTable();
            PageInfo.AddPageInfoRow((int.Parse(page_no) - 1) * int.Parse(page_size), int.Parse(page_size));

            inBlock.Tables.Add("PageInfo"); //后台需要
            inBlock.Tables["PageInfo"].Merge(PageInfo);

            string svr = "pmmm02n_inq2"; ////高级查询
                                        //if (type_inq=="1")
                                        //{
                                        //    svr = "pmmm02n_inq2"; 
                                        //}

            EI.EIInfo outBlock = EI.EITuxedo.CallService(svr, inBlock);


             


            string sql_str1 = "    select code,code_desc_1_content from tep0002   where code_class = 'QMQK' "
                              + "   and code_desc_2_content like '%N%'   ";
            //仓库代码转换
            EI.EIInfo outBlock_TEMP = EF.Utility.ExecQuery(sql_str1); //QUAL_GRADE_CODE


            //小代码转换；
           // EI.EIInfo outBlock_TEMP2 = EF.Utility.GetCodeClassValue("MM08"); //SHIFT_GROUP


            DataTable dtTemp = null;


            for (int i = outBlock.Tables[0].Rows.Count - 1; i >= 0; i--)
            {
                string qual_grade_code = outBlock.Tables[0].Rows[i]["QUAL_GRADE_CODE"].ToString().Trim();
                if (qual_grade_code.Trim() != "")
                {
                    if (outBlock_TEMP.Tables[0].Select("CODE  = '" + qual_grade_code + "'").Count<DataRow>() == 1)
                    {
                        dtTemp = outBlock_TEMP.Tables[0].Select("CODE  = '" + qual_grade_code + "'").CopyToDataTable<DataRow>();
                        outBlock.Tables[0].Rows[i]["QUAL_GRADE_NAME"] = dtTemp.Rows[0]["CODE_DESC_1_CONTENT"];
                    }
                }
                //string shift_group = outBlock.Tables[0].Rows[i]["SHIFT_GROUP"].ToString().Trim();
                //if (shift_group.Trim() != "")
                //{
                //    if (outBlock_TEMP2.Tables[0].Select("CODE  = '" + shift_group + "'").Count<DataRow>() == 1)
                //    {
                //        dtTemp = outBlock_TEMP2.Tables[0].Select("CODE  = '" + shift_group + "'").CopyToDataTable<DataRow>();
                //        outBlock.Tables[0].Rows[i]["SHIFT_GROUP"] = dtTemp.Rows[0]["CODE_DESC_1_CONTENT"];
                //    }
                //}


                //UpDownFileFtpController ctr = new UpDownFileFtpController();
                //string mat_no = outBlock.Tables[0].Rows[i]["MAT_NO"].ToString();
                //int files_num = ctr.PostGetFilesNum("DCXA", mat_no, "");
                //outBlock.Tables[0].Rows[i]["FIELD_N1"] = files_num;



            }










            outBlock.Tables[0].TableName = "Table0";









            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;


        }







        //高级查询的查询条件获取，【主要是各类小代码，类似之前画面的初始化参数】
        [HttpPost]
        [Route("PostPmmm02n_Load")]
        public System.Data.DataSet PostPmmm02n_Load([FromBody]  JObject obj)
        {

            //产出类型
            string sql_str1  = "    select code,code_desc_1_content from tep0002   where code_class = 'QMQK' "
                              + "   and code_desc_2_content like '%N%'   ";
             
            EI.EIInfo outBlock = EF.Utility.ExecQuery(sql_str1); 

            outBlock.Tables[0].TableName = "QUAL_GRADE_CODE";


            //小代码转换；                       SHIFT_GROUP

            EI.EIInfo outBlock1 = EF.Utility.GetCodeClassValue("MM08");


            DataRow dr1 = outBlock1.Tables[0].NewRow();
            dr1["CODE"] = " ";
            dr1["CODE_DESC_1_CONTENT"] = " ";
            outBlock1.Tables[0].Rows.InsertAt(dr1, 0);



            outBlock1.Tables[0].TableName = "SHIFT_GROUP";



            //小组
            //      string sql_2 = "";
            //sql_2 = " select duty_maker from tpmmm05 where dptment_code = '" + this.dptment_code + "' ";
            //sql_2 += " and prod_kindtype = '" + this.unit_codeDevLookUpEdit.EditValue.ToString().Trim().Substring(2, 1) + "' ";
            //sql_2 += " and shift_group = '" + this.shift_groupDevLookUpEdit.EditValue + "' ";


            sql_str1 = " select duty_maker code ,duty_maker  code_desc_1_content  ,shift_group"
                    + "  from tpmmm05 where BRANCH_CODE='N' "
                    + " ";
            

            EI.EIInfo outBlock2 = EF.Utility.ExecQuery(sql_str1);
            outBlock2.Tables[0].TableName = "DUTY_MAKER";







            sql_str1 = "  select ' '  CODE , ' '   CODE_DESC_1_CONTENT from  dual  union     ";
            sql_str1 += "  select b.stock_no CODE ,stock_name  CODE_DESC_1_CONTENT from  tsimm01 b   ";
            sql_str1 += " where    b.stock_no  in ('NCB','NC1') ";

            EI.EIInfo outBlock3 = EF.Utility.ExecQuery(sql_str1);
            outBlock3.Tables[0].TableName = "STOCK_NO";





            sql_str1 = "  select code,code_desc_1_content from tep0002   where code_class = 'FIDP'   ";
            sql_str1 += " and code in  ('NA','NB','NC')  ";
            sql_str1 += " order by  code ";

            EI.EIInfo outBlock4 = EF.Utility.ExecQuery(sql_str1);



            DataRow dr2 = outBlock4.Tables[0].NewRow();
            dr2["CODE"] = " ";
            dr2["CODE_DESC_1_CONTENT"] = " ";
            outBlock4.Tables[0].Rows.InsertAt(dr2, 0);





            outBlock4.Tables[0].TableName = "DPTMENT_CODE";

 




            outBlock.Tables.Add(outBlock1.Tables[0].Copy());
            outBlock.Tables.Add(outBlock2.Tables[0].Copy());
            outBlock.Tables.Add(outBlock3.Tables[0].Copy());
            outBlock.Tables.Add(outBlock4.Tables[0].Copy());




            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;


        }


        [HttpPost]
        [Route("PostPmmm02n_pro")]

        //单记录操作：入库申请PA14 单记录操作；
        public System.Data.DataSet PostPmmm02n_pro([FromBody]  JObject obj)
        {
            //obj对象区分大小写的； obj["ASMAT_NAME"] 报错。
            EI.EIInfo inBlock = new EI.EIInfo();

            

            inBlock.Tables[0].Columns.Add("MAT_NO"); 
            inBlock.Tables[0].Columns.Add("LOCATION_NO");
            inBlock.Tables[0].Columns.Add("STOCK_NO");


            inBlock.Tables[0].Columns.Add("QUAL_GRADE_CODE");
            inBlock.Tables[0].Columns.Add("SHIFT_GROUP");
            inBlock.Tables[0].Columns.Add("DUTY_MAKER");
            inBlock.Tables[0].Columns.Add("OUT_TIME");


            

            inBlock.Tables[0].Rows.Add();
        

            inBlock.Tables[0].Rows[0]["MAT_NO"] = obj["MAT_NO"] == null ? " " : obj["MAT_NO"].ToString(); 
            inBlock.Tables[0].Rows[0]["LOCATION_NO"] = obj["LOCATION_NO"] == null ? " " : obj["LOCATION_NO"].ToString();
            inBlock.Tables[0].Rows[0]["STOCK_NO"] = obj["STOCK_NO"] == null ? " " : obj["STOCK_NO"].ToString();


            inBlock.Tables[0].Rows[0]["QUAL_GRADE_CODE"] = obj["QUAL_GRADE_CODE"] == null ? " " : obj["QUAL_GRADE_CODE"].ToString();
            inBlock.Tables[0].Rows[0]["SHIFT_GROUP"] = obj["SHIFT_GROUP"] == null ? " " : obj["SHIFT_GROUP"].ToString();
            inBlock.Tables[0].Rows[0]["DUTY_MAKER"] = obj["DUTY_MAKER"] == null ? " " : obj["DUTY_MAKER"].ToString();
            inBlock.Tables[0].Rows[0]["OUT_TIME"] = obj["OUT_TIME"] == null ? " " : obj["OUT_TIME"].ToString();



            string pro_type = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString().ToUpper();
            



            inBlock.sys_info.company_code        = "LT";
            inBlock.sys_info.company_name        = "LT";

            inBlock.sys_info.userid              = obj["USERID"].ToString();
            inBlock.sys_info.username            = obj["USERNAME"].ToString();
            inBlock.sys_info.formname            = obj["FORMNAME"].ToString();

            //pro_type  //产出入库申请PA14
            inBlock.Tables[0].TableName = pro_type;

             

         
            EI.EIInfo outBlock = EI.EITuxedo.CallService("pmmm02n_pro", inBlock);

            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;

        }
        

        [HttpPost]
        [Route("PostPmmm02n_pro_all")]
        //多记录操作：入库申请撤销 PB14  14->11； 入库确认PA19；
        public System.Data.DataSet PostPmmm02n_pro_all([FromBody]  JObject obj)
        {
            string USERID = obj["USERID"] == null ? " " : obj["USERID"].ToString();
            string USERNAME = obj["USERNAME"] == null ? " " : obj["USERNAME"].ToString();
            string FORMNAME = obj["FORMNAME"] == null ? " " : obj["FORMNAME"].ToString();
            string SRV = obj["SRV"] == null ? " " : obj["SRV"].ToString();



            DataTable table_rec = JsonConvert.DeserializeObject<DataTable>(obj["table_rec"].ToString(), new DingApi.ReadAheadDataTableConverter());;

            EI.EIInfo inBlock = new EI.EIInfo();
            inBlock.sys_info.company_code = "LT";
            inBlock.sys_info.company_name = "常熟市龙腾特种钢有限公司";

            inBlock.sys_info.userid = USERID;
            inBlock.sys_info.username = USERNAME;
            inBlock.sys_info.formname = FORMNAME;

            inBlock.Tables[0].Merge(table_rec);

            //PA11 入库申请回退（默认值）
            inBlock.Tables[0].TableName = "PA11";

            string svr_name = "";
            //修改或删除操作；
            if (SRV.Trim().Contains("PA") || SRV.Trim().Contains("PB"))
            {
                svr_name = "pmmm02n_pro";
                inBlock.Tables[0].TableName = SRV.Trim().ToUpper();
            }
            else
            {
                svr_name = SRV;
            }

            EI.EIInfo outBlock = EI.EITuxedo.CallService(svr_name, inBlock);


            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");

            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;


        }


        [HttpPost]
        [Route("PostPmmm02n_pro_all2")]
        //多记录操作：入库申请撤销 PB14  14->11； 入库确认PA19；
        public System.Data.DataSet PostPmmm02n_pro_all2([FromBody]  JObject obj)
        {
            //系统信息；
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");




            string USERID = obj["USERID"] == null ? " " : obj["USERID"].ToString();
            string USERNAME = obj["USERNAME"] == null ? " " : obj["USERNAME"].ToString();
            string FORMNAME = obj["FORMNAME"] == null ? " " : obj["FORMNAME"].ToString();
            string SRV = obj["SRV"] == null ? " " : obj["SRV"].ToString();



            DataTable table_rec = JsonConvert.DeserializeObject<DataTable>(obj["table_rec"].ToString(), new DingApi.ReadAheadDataTableConverter());;

            // 
            string sql_str1 = "select mat_no from tpmmm02n "
                        + " where status ='" + table_rec.Rows[0]["STATUS"].ToString() + "'"
                        + " and  prod_lot_no ='" + table_rec.Rows[0]["PROD_LOT_NO"].ToString() + "'"
                        + " and  QUAL_GRADE_CODE ='" + table_rec.Rows[0]["QUAL_GRADE_CODE"].ToString() + "'"
                        + " and  PACK_MODE_CODE ='" + table_rec.Rows[0]["PACK_MODE_CODE"].ToString() + "'"
                        + " and  SG_SIGN ='" + table_rec.Rows[0]["SG_SIGN"].ToString() + "'"
                        + " and  MAT_SPEC_DESC ='" + table_rec.Rows[0]["MAT_SPEC_DESC"].ToString() + "'"
                        + " and  SHIFT_GROUP ='" + table_rec.Rows[0]["SHIFT_GROUP"].ToString() + "'"
                        + " and  OUT_TIME ='" + table_rec.Rows[0]["OUT_TIME"].ToString() + "'"
                        + " order by   prod_lot_no, qual_grade_code, pack_mode_code,    sg_sign, mat_spec_desc,SHIFT_GROUP,OUT_TIME "
                        ;
             

            EI.EIInfo outBlock2 = EF.Utility.ExecQuery(sql_str1);

            if (outBlock2.Tables[0].Rows.Count != int.Parse(table_rec.Rows[0]["MAT_NUM"].ToString()))
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "数量不一致，请刷新后重试");
                return outBlock;
            }
         




            EI.EIInfo inBlock = new EI.EIInfo();
            inBlock.sys_info.company_code = "LT";
            inBlock.sys_info.company_name = "常熟市龙腾特种钢有限公司";

            inBlock.sys_info.userid = USERID;
            inBlock.sys_info.username = USERNAME;
            inBlock.sys_info.formname = FORMNAME;

            inBlock.Tables[0].Merge(outBlock2.Tables[0]);

            //PA11 入库申请回退（默认值）
            inBlock.Tables[0].TableName = "PA11";

            string svr_name = "";
            //修改或删除操作；
            if (SRV.Trim().Contains("PA") || SRV.Trim().Contains("PB"))
            {
                svr_name = "pmmm02n_pro";
                inBlock.Tables[0].TableName = SRV.Trim().ToUpper();
            }
            else
            {
                svr_name = SRV;
            }

           

            EI.EIInfo outBlock3 = EI.EITuxedo.CallService(svr_name, inBlock);
            if (outBlock3.sys_info.flag != 0)
            {
                outBlock.Tables["SYS"].Rows.Add(outBlock3.sys_info.flag, outBlock3.sys_info.msg);
                return outBlock;
            }
            else
            { 
                outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, "操作成功！");
                return outBlock;
            }




            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;


        }

        

        [HttpPost]
        [Route("PostPmmm02n_save2")]


        //库位变更、类别变更
        public System.Data.DataSet PostPmmm02n_save2([FromBody]  JObject obj)
        {


            //obj对象区分大小写的； obj["ASMAT_NAME"] 报错。
            EI.EIInfo inBlock = new EI.EIInfo();


             

            inBlock.Tables[0].Columns.Add("COMPANY_CODE");
            inBlock.Tables[0].Columns.Add("ASMAT_NO");
            inBlock.Tables[0].Columns.Add("STOCK_NO");
            inBlock.Tables[0].Columns.Add("ASMAT_BIG_TYPE");
            inBlock.Tables[0].Columns.Add("ASMAT_BIG_NAME");
            inBlock.Tables[0].Columns.Add("ASMAT_SMALL_TYPE");
            inBlock.Tables[0].Columns.Add("ASMAT_SMALL_NAME");
            inBlock.Tables[0].Columns.Add("PA_LOCATION_NO");
            inBlock.Tables[0].Columns.Add("REMARK");
            inBlock.Tables[0].Columns.Add("USE_PLACE");
            inBlock.Tables[0].Columns.Add("DPTMENT_CODE");


            inBlock.Tables[0].Columns.Add("COMPANY_CNAME");

           
          

            inBlock.Tables[0].Rows.Add();
            inBlock.Tables[0].Rows[0]["COMPANY_CODE"] = obj["COMPANY_CODE"] == null ? " " : obj["COMPANY_CODE"].ToString();
            inBlock.Tables[0].Rows[0]["ASMAT_NO"] = obj["ASMAT_NO"] == null ? " " : obj["ASMAT_NO"].ToString();
            inBlock.Tables[0].Rows[0]["STOCK_NO"] = obj["STOCK_NO"] == null ? " " : obj["STOCK_NO"].ToString();

            inBlock.Tables[0].Rows[0]["ASMAT_BIG_TYPE"] = obj["ASMAT_BIG_TYPE"] == null ? " " : obj["ASMAT_BIG_TYPE"].ToString();
            inBlock.Tables[0].Rows[0]["ASMAT_BIG_NAME"] = obj["ASMAT_BIG_NAME"] == null ? " " : obj["ASMAT_BIG_NAME"].ToString();
            inBlock.Tables[0].Rows[0]["ASMAT_SMALL_TYPE"] = obj["ASMAT_SMALL_TYPE"] == null ? " " : obj["ASMAT_SMALL_TYPE"].ToString();
            inBlock.Tables[0].Rows[0]["ASMAT_SMALL_NAME"] = obj["ASMAT_SMALL_NAME"] == null ? " " : obj["ASMAT_SMALL_NAME"].ToString();
            inBlock.Tables[0].Rows[0]["PA_LOCATION_NO"] = obj["PA_LOCATION_NO"] == null ? " " : obj["PA_LOCATION_NO"].ToString();
            inBlock.Tables[0].Rows[0]["REMARK"] = obj["REMARK"] == null ? " " : obj["REMARK"].ToString();
            inBlock.Tables[0].Rows[0]["USE_PLACE"] = obj["USE_PLACE"] == null ? " " : obj["USE_PLACE"].ToString();
            inBlock.Tables[0].Rows[0]["DPTMENT_CODE"] = obj["DPTMENT_CODE"] == null ? " " : obj["DPTMENT_CODE"].ToString();


            //修改之前的类别           
            inBlock.Tables[0].Rows[0]["COMPANY_CNAME"] = obj["COMPANY_CNAME"] == null ? " " : obj["COMPANY_CNAME"].ToString();


    



            string srv = obj["SRV"] == null ? " " : obj["SRV"].ToString();
          

            //块0为删除；
            //块1为新增
            //块2为修改
            EI.EIInfo inBlock2 = new EI.EIInfo();
            inBlock2.sys_info.company_code = "LT";
            inBlock2.sys_info.company_name = "龙腾特钢";

            inBlock2.sys_info.userid = obj["USERID"].ToString();
            inBlock2.sys_info.username = obj["USERNAME"].ToString();
            inBlock2.sys_info.formname = obj["FORMNAME"].ToString();


            //inBlock2.Tables.Add();
            //inBlock2.Tables.Add();

            //库位变更
            if (srv.Contains("pabmb1_save"))
            {
                //inBlock2.Tables.Add(inBlock.Tables[0].Copy());
                inBlock2.Tables[0].Merge(inBlock.Tables[0].Copy());

                inBlock2.Tables[0].TableName = "INS_UPD";


            }

            //类别变更
            else if (srv.Contains("pa0006_save"))
            {
                //inBlock2.Tables.Add(inBlock.Tables[0].Copy());
                inBlock2.Tables[0].Merge(inBlock.Tables[0].Copy());
                inBlock2.Tables[0].TableName = "UPD_TYPE";
            }

            else if (srv.Contains("pa0006_upd1"))
            {
                //inBlock2.Tables.Add(inBlock.Tables[0].Copy());
                inBlock2.Tables[0].Merge(inBlock.Tables[0].Copy());
                inBlock2.Tables[0].TableName = "UPD1";
                srv = "pa0006_save";
            }

          



            //STOCK_NO,ASMAT_NO,ASMAT_BIG_TYPE,ASMAT_SMALL_TYPE,ASMAT_BIG_NAME,ASMAT_SMALL_NAME
            EI.EIInfo outBlock = EI.EITuxedo.CallService(srv, inBlock2);


            //srv = "dcjl42_pass";
            //srv = "dcjl42_reback";


          






            //系统信息；
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
            return outBlock;

        }

    }
}